package com.fx.apps;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.kernal.smartvision.activity.SmartvisionCameraActivity;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 原生模块Java代码
 */
public class OCRModule extends AppCompatActivity {
    //扫描识别请求码
    private final static int SCAN_REQUEST_CODE = 101;
    //导入识别请求码
    private final static int IMPORT_REQUEST_CODE = 102;

    //识别结果
    private String recogResult;
    //识别成功后图片路径（默认为裁切图片）
    private String resultPic;
    //敏感区域图片路径
    private String uploadPicPath;
    //表示识别类型,0:vin码 1：手机号
    private int ocrType;

    public void getTime(Context ctx) {
        SimpleDateFormat formatDate=new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
        Date date=new Date(System.currentTimeMillis());   //获取当前时间
        String s=formatDate.format(date);
        Log.e("HHH",s);
        Toast.makeText(ctx, s, Toast.LENGTH_SHORT).show();
    }

    /**
     * 调用ocr识别
     */
    public void showOCR(Context ctx) {
        Intent cameraIntent = new Intent(ctx, SmartvisionCameraActivity.class);
        ctx.startActivity(cameraIntent);
//        startActivityForResult(cameraIntent, SCAN_REQUEST_CODE);
    }



    /**
     * 获取识别结果
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        switch (requestCode) {
            //扫描识别结果
            case SCAN_REQUEST_CODE:
                if (resultCode == RESULT_OK) {
                    Log.e("ocr", "识别结果");
//                    setContentView(R.layout.activity_blank);
//                    recogResult = data.getStringExtra("RecogResult");
//                    resultPic = data.getStringExtra("resultPic");
//                    uploadPicPath = data.getStringExtra("uploadPicPath");
//                    ocrType = data.getIntExtra("ocrType", 0);
//                    gotoResultPage(SCAN_REQUEST_CODE);
                }
                break;
            //导入识别结果
            case IMPORT_REQUEST_CODE:
                if (resultCode == RESULT_OK) {
                    Log.e("ocr", "识别结果22");
//                    recogResult = data.getStringExtra("RecogResult");
//                    resultPic = data.getStringExtra("resultPic");
//                    uploadPicPath = data.getStringExtra("uploadPicPath");
//                    ocrType = data.getIntExtra("ocrType", 0);
//                    gotoResultPage(IMPORT_REQUSET_CODE);
                }
                break;
            default:
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

}
